package com.bdqn.t362.pay.servlet;

import com.bdqn.t362.order.entity.TB2COrder;
import com.bdqn.t362.order.service.TB2COrderService;
import com.bdqn.t362.order.service.impl.TB2COrderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author lqm
 * @ClassName ${NAME}
 * @description: 支付成功回调路径
 */
@WebServlet("/PayCallBackServlet")
public class PayCallBackServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String out_trade_no = request.getParameter("out_trade_no");

        //修改订单状态
        TB2COrderService tb2COrderService = new TB2COrderServiceImpl();

        int count = tb2COrderService.updateOrder(out_trade_no,"1");
        PrintWriter out = response.getWriter();
        if(count>0){
            request.getRequestDispatcher("").forward(request,response);
            out.print("<script>alert('购买成功！'); location.href='前端首页';</script>");
        }else{
            out.print("<script>alert('购买失败！'); location.href='前端首页';</script>");
        }


    }
}
